package com.yuntuzhilian.chapter5.demo3;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author MrWang-shuizhishuiheshui
 * @description 服务器--提供服务
 */
public class ServerTest {
    public static void main(String[] args) {
        ServerSocket serverSocket=null;
        Socket socket =null;
        try {
            //1创建ServerSocket对象,指定端口号
            serverSocket=new ServerSocket(8000);
            //涉及到监听多个客户端请求,循环监听
            while(true){
                //2.监听客户端的请求
                socket = serverSocket.accept();
                //3.创建线程,开启站点socket
                LoginThread loginThread=new LoginThread(socket);
                //4.启动线程,让线程和客户端通信
                loginThread.start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                serverSocket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
